<?php

function anons_news(){
    
    $q=mysql_query('select * from news where `vis`=1 order by cdate desc limit 0,5')or die(mysql_error());
    $i=0;
    while ($r=  mysql_fetch_assoc($q)){
        if ($i>0)
         echo '<hr/>';
        $i=1;
        if (empty($r['description'])){
            echo '<p class="item">'.typo($r['title']).'</p>';
        }else{
            if (preg_match('#a#', $r['title'])) {
               	$r['title'] = ereg_replace('#a#', '<a href="/news/' . $r['id'] . '.html">', $r['title']);
                if (preg_match('#/a#', $r['title']))
                    $r['title'] = ereg_replace('#/a#', '</a>', $r['title']);
                elseif (preg_match('##', $r['title']))
                    $r['title'] = ereg_replace('##', '</a>', $r['title']);                
                else
                    $r['title'] .= '</a>';
                echo '<p class="item">'.typo($r['title']).'</p>';
            }else{
                echo '<p class="item"><a href="/news/' . $r['id'] . '.html">'.$r['title'].'</a></p>';
            }
        }
            if ($_SESSION['level'] >= 5){ 
             echo '<div style="text-align:right;"><a href="/ADM/edit/' . $r['id'] . '/?vid=news" style="color: red; font-size:10px;">Редактировать</a></div>';
            }
        
    }
    
}
function news_page($type, $path){
    if (empty($path[2])){
        if ($type=='title'){
            echo 'Новости';
        }
        if ($type=='content'){
            
            echo anons_news();
        }
    }else{
        $q=mysql_query('select * from news where vis=1 and id='.$path[2])or die(mysql_error());
        $data=  mysql_fetch_assoc($q);
        if ($type=='title'){
            echo typo($data['title']);
        }
        if ($type=='content'){
            if ($_SESSION['level'] >= 5){ 
             echo '<div ondblclick="parent.location=\'/ADM/edit/' . $data['id'] . '/?vid=news\'" title="Кликните дважды для редактирования">
                            <a href="/ADM/delete/'.$data['id'].'/?vid=news">Удалить</a>
                ';
             echo '<a href="/ADM/edit/' . $data['id'] . '/?vid=news" style="color: red">Редактировать</a><br />';
            }
            echo $data['description'];
        }
        
    }
    
}
?>
